import java.util.*;
import java.util.stream.Collectors;

/**
 * @description:
 * @Author: wuzhenbin
 * @CreateTime: 2025-02-07
 */
public class leetcode_128 {
    public static void main(String[] args) {
        int[] ints = {0, 1, 1, 2, 3};
        System.out.println(longestConsecutive(ints));
    }

    public static int longestConsecutive(int[] nums) {

        //优雅转换 装箱
        List<Integer> list1 = Arrays.stream(nums).boxed().collect(Collectors.toList());
        HashSet<Integer> list2 = new HashSet<>(list1);
        ArrayList<Integer> list = new ArrayList<>(list2);
        list.sort(Integer::compareTo);
        int count = 0;
        for (int i = 0; i < list.size(); i++) {
            int tmp = 1;
            while (i < list.size()-1 && list.get(i)==list.get(i+1)-1){
                i++;
                tmp++;
            }
            count = Math.max(tmp,count);
        }
        return count;
    }
}
